﻿
@{
    ViewBag.Title = "商品";
}
@section CSS{

}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            @ViewBag.tName
            <small>商品列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">商品管理</a></li>
            <li class="active">@ViewBag.tName 商品列表</li>
        </ol>
    </section>
    <section style="display:none;">
        <div class="col-xs-12">
            <div class="box box-primary ">
                <!-- form start -->
                <form class="form-horizontal">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">商品名称</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="title" placeholder="商品名称">
                            </div>
                            <label for="shopName" class="col-sm-2 control-label">店铺名称</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="shopName" placeholder="店铺名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="code" class="col-sm-2 control-label">商品编号</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="code" placeholder="商品编号">
                            </div>
                            <label for="category" class="col-sm-2 control-label">类别</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="category" placeholder="类别">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputUName" class="col-sm-2 control-label">商品状态</label>
                            <div class="col-sm-2">
                                <select class="form-control" id="classSelect">
                                    <option value="-1">-请选择状态-</option>
                                    <option value="1">上架</option>
                                    <option value="0">下架</option>
                                </select>
                            </div>
                            <label for="inputUName" class="col-sm-2 control-label">添加日期</label>
                            <div class="col-sm-2">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" id="startTime">
                                </div>
                            </div>
                            <label style="float:left;"> - </label>
                            <div class="col-sm-2">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" id="endTime">
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer ">
                        <button type="button" class="btn btn-primary btn-search center-block" id="btnSearch"><i class="fa fa-search"></i> 查询</button>
                        @*<button type="button" class="btn btn-danger" id="btnDelMul"><i class="fa fa-remove"></i> 批量删除</button>*@
                        @*<button type="button" class="btn btn-success" id="btnExport"><i class="fa fa-download"></i> 导出Excel</button>*@
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-3">
                <a href="compose.html" class="btn btn-primary btn-block margin-bottom">Compose</a>

                <div class="box box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">Folders</h3>

                        <div class="box-tools">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                                <i class="fa fa-minus"></i>
                            </button>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        <ul class="nav nav-pills nav-stacked">
                            <li class="active">
                                <a href="#">
                                    <i class="fa fa-inbox"></i> Inbox
                                    <span class="label label-primary pull-right">12</span>
                                </a>
                            </li>
                            <li><a href="#"><i class="fa fa-envelope-o"></i> Sent</a></li>
                            <li><a href="#"><i class="fa fa-file-text-o"></i> Drafts</a></li>
                            <li>
                                <a href="#"><i class="fa fa-filter"></i> Junk <span class="label label-warning pull-right">65</span></a>
                            </li>
                            <li><a href="#"><i class="fa fa-trash-o"></i> Trash</a></li>
                        </ul>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /. box -->
                <div class="box box-solid">
                    <div class="box-header with-border">
                        <h3 class="box-title">Labels</h3>

                        <div class="box-tools">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse">
                                <i class="fa fa-minus"></i>
                            </button>
                        </div>
                    </div>
                    <div class="box-body no-padding">
                        <ul class="nav nav-pills nav-stacked">
                            <li><a href="#"><i class="fa fa-circle-o text-red"></i> Important</a></li>
                            <li><a href="#"><i class="fa fa-circle-o text-yellow"></i> Promotions</a></li>
                            <li><a href="#"><i class="fa fa-circle-o text-light-blue"></i> Social</a></li>
                        </ul>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <div class="col-md-9">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">商品</h3>
                        <div class="box-tools pull-right">
                            <div class="has-feedback">
                                <input type="text" class="form-control input-sm" placeholder="商品名称">
                                <span class="glyphicon glyphicon-search form-control-feedback"></span>
                            </div>
                        </div>
                        <!-- /.box-tools -->
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body no-padding">
                        <div class="table-responsive mailbox-messages">
                            <table id="DataList" class="table table-hover table-striped">
                                <thead>
                                    <tr>
                                        <th>
                                            <button type="button" class="btn btn-default btn-sm checkbox-toggle">
                                                <i class="fa fa-square-o"></i>
                                            </button>
                                        </th>
                                        <th>商品编号</th>
                                        <th width="220px">商品名称</th>
                                        <th>商品类别</th>
                                        <th>店铺名称</th>
                                        <th>@(ViewBag.tid == 2 ? "结算价" : "平台价")</th>                                        
                                        <th>添加时间</th>
                                    </tr>
                                </thead>
                                <tbody> </tbody>
                            </table>
                            <!-- /.table -->
                        </div>
                        <!-- /.mail-box-messages -->
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer no-padding">
                        <div class="mailbox-controls">
                            <!-- Check all button -->
                            <button type="button" class="btn btn-default btn-sm checkbox-toggle">
                                <i class="fa fa-square-o"></i>
                            </button>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default btn-sm"><i class="fa fa-trash-o"></i></button>
                                <button type="button" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></button>
                                <button type="button" class="btn btn-default btn-sm"><i class="fa fa-share"></i></button>
                            </div>
                            <!-- /.btn-group -->
                            <button type="button" class="btn btn-default btn-sm"><i class="fa fa-refresh"></i></button>
                            <!-- /.pull-right -->
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
@section JS{
    <script>
    function UpdateImgSize(id) {
        $.ajax({
            type: 'post',
            url: "/goods/GetSpecWithValue/" + id,
            data: {  },
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data != null) {
                    if (data.img_spec.value_list != null && data.img_spec.value_list.length > 0)  {
                        $.each(data.img_spec.value_list, function (s, value) {
                            $.ajax({
                                type: 'POST',
                                url: domain + "/Tools/Create210_210Img",
                                data: { path: value.thumb_url },
                                dataType: 'json',
                                success: function (data) {
                                    //console.log(data);
                                },
                            });
                        });
                    }
                }
            },
        });
        $.ajax({
            type: 'post',
            url: "/goods/GetGoodsSkuList/" + id,
            data: {  },
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data != null && data.length > 0)  {
                    $.each(data, function (s, value) {
                        $.ajax({
                            type: 'POST',
                            url: domain + "/Tools/Create210_210Img",
                            data: { path: value.thumb_url },
                            dataType: 'json',
                            success: function (data) {
                                //console.log(data);
                            },
                        });
                    });
                }

            },
        });
    }

        $(function () {
            //初始化表格
            GenerateTable();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                    console.log();
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#btnSearch").on("click", function () {
                var datemin = $('#startTime').val();
                var datemax = $("#endTime").val();
                if ((datemin == null && datemax != null) || (datemin != null && datemax == null)) {
                    layer.msg('请把时间填充完整!', { icon: 1, time: 1000 });
                }
                else {
                    u_table.fnDestroy();
                    GenerateTable();
                }
            });

            $('#startTime').datepicker({
                autoclose: true
            });

            $('#endTime').datepicker({
                autoclose: true
            });
        });
        var tid=@ViewBag.tid;
        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": true,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "fnServerParams": function (aoData) {
                    var classSelect = $("#classSelect").val();
                    var datemin = $('#startTime').val();
                    var datemax = $("#endTime").val();
                    var title = $("#title").val();
                    var shopName = $("#shopName").val();
                    var code = $("#code").val();
                    var category = $("#category").val();
                    aoData.push(
                        { "name": "dateMin", "value": datemin },
                        { "name": "dateMax", "value": datemax },
                        { "name": "title", "value": title },
                        { "name": "shopName", "value": shopName },
                         { "name": "code", "value": code },
                          { "name": "category", "value": category },
                        { "name": "type", "value": tid },
                        { "name": "status", "value": classSelect }
                    );
                },
                "sAjaxSource": "/goods/GoodsList",
                "aoColumns": [
                     { "mDataProp": 'id', "mRender": function (data, type, full) {
                             return '<div class="icheckbox_flat-blue" aria-checked="false" aria-disabled="false" style="position: relative;"><input type="checkbox" style="position: absolute; opacity: 0;"><ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins></div>';
                         }
                      },
                     { "mDataProp": 'id' },
                     {
                         "mDataProp": 'name', "mRender": function (data, type, full) {
                             //return data.length>6?(data.substring(0,6)+"…") :data;
                             return data;
                         }
                     },
                    { "mDataProp": 'categoryName' },
                    { "mDataProp": 'shopName' },
                    { "mDataProp": 'sale_price' },
                    {
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD HH:mm:ss");
                        }
                    }
                ]
            });
        }

        /*上架*/
        function goods_pass(obj, id) {
            layer.confirm('确定上架商品？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("上架").attr("onClick", "goods_noPass(this," + id + ")").attr("title", "点击下架").attr("class", "btn btn-success");
                            layer.msg('已上架', { icon: 6, time: 1000 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }
        /*下架*/
        function goods_noPass(obj, id) {
            layer.confirm('确定下架商品？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("下架").attr("onClick", "goods_pass(this," + id + ")").attr("title", "点击上架").attr("class", "btn btn-danger");
                            layer.msg('已下架', { icon: 5, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }

          /*设为新品*/
        function goods_new(obj, id) {
            layer.confirm('确定设为新品？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsNew",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("新品").attr("onClick", "goods_noNew(this," + id + ")").attr("title", "点击启用").attr("class", "btn btn-warning");
                            layer.msg('已设为新品', { icon: 6, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }
        /*取消新品*/
        function goods_noNew(obj, id) {
            layer.confirm('确定取消新品设置？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsNew",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("普通").attr("onClick", "goods_new(this," + id + ")").attr("title", "点击设为新品").attr("class", "btn btn-info");
                            layer.msg('已取消', { icon: 5, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }

          /*置顶*/
        function goods_top(obj, id) {
            layer.confirm('确定置顶？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsTop",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("置顶").attr("onClick", "goods_noTop(this," + id + ")").attr("title", "点击取消置顶").attr("class", "btn btn-warning");
                            layer.msg('已置顶', { icon: 6, time: 1000 });
                        }
                        else {
                            alert(data.info);
                        }
                    }
                });

            });
        }
        /*取消置顶*/
        function goods_noTop(obj, id) {
            layer.confirm('确定取消置顶？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetGoodsIsTop",
                    dataType: "json",
                    data: { id: id, isUse: 0 },
                    success: function (data) {
                        if (data.status == "y") {
                            $(obj).text("常规").attr("onClick", "goods_top(this," + id + ")").attr("title", "点击置顶").attr("class", "btn btn-info");
                            layer.msg('已取消置顶', { icon: 5, time: 1200 });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1200 });
                        }
                    }
                });

            });
        }
    </script>
}

